package com.muyu.system.controller;


import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.system.domain.DanmoUserStore;
import com.muyu.system.service.IDanmoUserStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 店铺关注Controller
 * 
 * @author  yangle
 * @date 2025-03-24
 */
@RestController
@RequestMapping("/userStore")
public class DanmoUserStoreController extends BaseController
{
    @Autowired
    private IDanmoUserStoreService danmoUserStoreService;

    /**
     * 查询店铺关注列表
     */
//    @RequiresPermissions("system:userStore:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoUserStore>> list(DanmoUserStore danmoUserStore)
    {
        startPage();
        List<DanmoUserStore> list = danmoUserStoreService.selectDanmoUserStoreList(danmoUserStore);
        return getDataTable(list);
    }

    /**
     * 导出店铺关注列表
     */
//    @RequiresPermissions("system:userStore:export")
    @Log(title = "店铺关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoUserStore danmoUserStore)
    {
        List<DanmoUserStore> list = danmoUserStoreService.selectDanmoUserStoreList(danmoUserStore);
        ExcelUtil<DanmoUserStore> util = new ExcelUtil<DanmoUserStore>(DanmoUserStore.class);
        util.exportExcel(response, list, "店铺关注数据");
    }

    /**
     * 获取店铺关注详细信息
     */
//    @RequiresPermissions("system:userStore:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoUserStoreService.selectDanmoUserStoreById(id));
    }

    /**
     * 新增店铺关注
     */
//    @RequiresPermissions("system:userStore:add")
    @Log(title = "店铺关注", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody DanmoUserStore danmoUserStore)
    {

        return danmoUserStoreService.insertDanmoUserStore(danmoUserStore);
    }

    /**
     * 修改店铺关注
     */
//    @RequiresPermissions("system:userStore:edit")
    @Log(title = "店铺关注", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoUserStore danmoUserStore)
    {
        return danmoUserStoreService.updateDanmoUserStore(danmoUserStore);
    }

    /**
     * 删除店铺关注
     */
//    @RequiresPermissions("system:userStore:remove")
    @Log(title = "店铺关注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return danmoUserStoreService.deleteDanmoUserStoreByIds(ids);
    }

    /**
     * 查询自己的粉丝
     */
    @GetMapping("/followerList")
    public Result followerList() {

        List<DanmoUserStore> list = danmoUserStoreService.selectFollowerList();
        if (list.size() == 0) {
            return Result.error("暂无粉丝");
        }
        PageInfo<DanmoUserStore> danmoUserFollowsPageInfo = new PageInfo<>(list);
        return Result.success(danmoUserFollowsPageInfo);
    }

    /**
     * 查询自己的关注的店铺
     */
    @GetMapping("/followList")
    public Result followList() {

        List<DanmoUserStore> list = danmoUserStoreService.selectFollowList();
        if (list.size() == 0) {
            return Result.error("暂无关注店铺");
        }
        PageInfo<DanmoUserStore> danmoUserFollowsPageInfo = new PageInfo<>(list);
        return Result.success(danmoUserFollowsPageInfo);
    }


    /**
     * 取消关注
     */
    @PostMapping("/deleteUserFlagship")
    public Result deleteUserFlagship(@RequestBody DanmoUserStore danmoUserStore) {


        return danmoUserStoreService.deleteUserFlagship(danmoUserStore);
    }
}
